﻿Imports CrystalDataHub.BLL
Imports Crystal.CLL


Public Class SourceData
#Region "Declare"

    Private mclsSourceDateManager As New SourceDataManager
    Public mdateSourceDate As Date
    Public mstrGenericSource As String
    Public mstrClientSpecificSource As String
    Public mblnSaved As Boolean = False
#End Region
#Region "Constructor"

    Public Sub New()
        InitializeComponent()
        GetValidatedControls()
    End Sub

#End Region

#Region "Events"

    ''' <summary>
    ''' Event form close.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub SourceData_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Dispose()
    End Sub

    ''' <summary>
    ''' Load the form.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub SourceData_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If mdateSourceDate.ToString <> String.Empty AndAlso mdateSourceDate <> Date.MinValue Then
            dtSourceDate.Value = mdateSourceDate
        End If
        txtGenericSource.Text = mstrGenericSource
        txtClientSpecific.Text = mstrClientSpecificSource
    End Sub

    '''
    ''' <summary>
    ''' Ok Click change the value on Data Hub screen.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        If dtSourceDate.Value Is Nothing Then
            ShowMessageBox(DBResult.DH_SOURCEDATE_INVALID)
            'MessageBox.Show(MessageManager.GetMessage(Crystal.CLL.DBResult.DH_SOURCEDATE_INVALID.ToString), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If txtClientSpecific.Text.Trim = String.Empty AndAlso txtGenericSource.Text.Trim = String.Empty Then
            ShowMessageBox(DBResult.DH_SOURCE_OPTION)
            'MessageBox.Show(MessageManager.GetMessage(Crystal.CLL.DBResult.DH_SOURCE_OPTION.ToString), BaseClass.crystalCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If dtSourceDate.IsDateValid Then
            mdateSourceDate = dtSourceDate.Value
            'Else
            '    ShowMessageBox(MessageManager.GetMessage(Crystal.CLL.DBResult.DH_SOURCEDATE_INVALID.ToString))
            '    Exit Sub
        End If
        
        mstrClientSpecificSource = txtClientSpecific.Text
        mstrGenericSource = txtGenericSource.Text
        mblnSaved = True
        Me.Close()
    End Sub

    ''' <summary>
    ''' Close the form on click of button cancel click.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

#End Region

#Region "Methods"

    ''' <summary>
    ''' Apply the validation.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GetValidatedControls()
        RequiredDateTimeControl(dtSourceDate, "Source date")
    End Sub

#End Region
End Class